<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="118px"
    >
      <el-form-item label="区县分公司" prop="districtCompany">
        <el-input
          v-model="queryParams.districtCompany"
          placeholder="请输入区县分公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业部" prop="businessDepartment">
        <el-input
          v-model="queryParams.businessDepartment"
          placeholder="请输入营业部"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小区名称" prop="communityName">
        <el-input
          v-model="queryParams.communityName"
          placeholder="请输入小区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

<!--      <el-form-item label="状态" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="请选择状态"-->
<!--          clearable-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.distance_target"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <!--   <el-form-item label="小区部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入小区部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="营销时间" prop="marketingTime">
        <el-input
          v-model="queryParams.marketingTime"
          placeholder="请输入营销时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小区状态" prop="communityStatus">
        <el-select
          v-model="queryParams.communityStatus"
          placeholder="请选择小区状态"
          clearable
          @change="handleStatusChange"
        >
          <el-option label="全部" value="" />
          <el-option label="已完成" value="0" />
          <el-option label="计划开展" value="1" />
        </el-select>
      </el-form-item>
      <!--  <el-form-item label="FTTR目标值(%)" prop="fttrTarget">
        <el-input
          v-model="queryParams.fttrTarget"
          placeholder="请输入FTTR目标值(%)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渗透率目标值(%)" prop="penetrationRate">
        <el-input
          v-model="queryParams.penetrationRate"
          placeholder="请输入渗透率目标值(%)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="融合目标数量" prop="convergenceTarget">
        <el-input
          v-model="queryParams.convergenceTarget"
          placeholder="请输入融合目标数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单宽带目标数量" prop="singleBroadbandTarget">
        <el-input
          v-model="queryParams.singleBroadbandTarget"
          placeholder="请输入单宽带目标数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:target:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:target:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:target:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:target:import']"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:target:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="targetList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="目标ID" align="center" prop="id" />
      <el-table-column
        label="区县分公司"
        align="center"
        prop="districtCompany"
      />
      <el-table-column
        label="营业部"
        align="center"
        prop="businessDepartment"
      />
      <el-table-column label="小区名称" align="center" prop="communityName" />
      <!-- <el-table-column label="小区部门id" align="center" prop="deptId" /> -->
      <!-- <el-table-column label="营销时间" align="center" prop="marketingTime" /> -->
      <el-table-column label="活动开始时间" align="center" prop="activityStartTime" />
      <el-table-column label="活动结束时间" align="center" prop="activityEndTime" />
      <el-table-column label="FTTR目标值" align="center" prop="fttrTarget" />
      <el-table-column
        label="渗透率目标值(%)"
        align="center"
        prop="penetrationRate"
      />
      <el-table-column
        label="融合目标数量"
        align="center"
        prop="convergenceTarget"
      />
      <el-table-column
        label="单宽带目标数量"
        align="center"
        prop="singleBroadbandTarget"
      />
      <el-table-column label="绑粉数" align="center" prop="fans" />
      <el-table-column label="套餐类型视频AI" align="center" prop="videoAiPackage" />
      <el-table-column label="核券量目标" align="center" prop="qualityRepair" />
      <el-table-column label="老旧终端升级" align="center" prop="oldTerminalUpgrade" />
      <el-table-column label="老旧套餐升级" align="center" prop="oldPackageUpgrade" />

<!--      <el-table-column label="状态" align="center" prop="status">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag-->
<!--            :options="dict.type.distance_target"-->
<!--            :value="scope.row.status"-->
<!--          />-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:target:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:target:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改小区业务目标对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="区县分公司" prop="districtCompany">
              <el-input
                v-model="form.districtCompany"
                placeholder="请输入区县分公司"
              /> </el-form-item
          ></el-col>
          <el-col :span="12"
            ><el-form-item label="营业部" prop="businessDepartment">
              <el-input
                v-model="form.businessDepartment"
                placeholder="请输入营业部"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="小区名称" prop="communityName">
              <el-select
                v-model="form.communityName"
                placeholder="请选择小区名称"
                style="width: 100%"
                @change="handleCommunityChange"
              >
                <el-option
                  v-for="community in communityList"
                  :key="community.deptId"
                  :label="community.deptName"
                  :value="community.deptName"
                  :data-dept-id="community.deptId"
                />
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="小区部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入小区部门id" />
        </el-form-item> --></el-col
          >
          <!-- 营销时间字段已隐藏 -->
          <el-col :span="12" style="display: none;">
            <el-form-item label="营销时间" prop="marketingTime">
              <el-input
                v-model="form.marketingTime"
                placeholder="请输入营销时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="活动开始时间" prop="activityStartTime">
              <el-date-picker
                v-model="form.activityStartTime"
                type="date"
                placeholder="请选择活动开始时间"
                clearable
                style="width: 100%"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                @change="calculateActivityDays"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="活动结束时间" prop="activityEndTime">
              <el-date-picker
                v-model="form.activityEndTime"
                type="date"
                placeholder="请选择活动结束时间"
                clearable
                style="width: 100%"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                @change="calculateActivityDays"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12"
            ><el-form-item label="FTTR目标值" prop="fttrTarget">
              <el-input
                v-model="form.fttrTarget"
                placeholder="请输入FTTR目标值"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="渗透率目标值(%)" prop="penetrationRate">
              <el-input
                v-model="form.penetrationRate"
                placeholder="请输入渗透率目标值(%)"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="融合目标数量" prop="convergenceTarget">
              <el-input
                v-model="form.convergenceTarget"
                placeholder="请输入融合目标数量"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单宽带目标数量" prop="singleBroadbandTarget">
              <el-input
                v-model="form.singleBroadbandTarget"
                placeholder="请输入单宽带目标数量"
              />
            </el-form-item>

            <!--  <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item> --></el-col
          >
          <el-col :span="12">
            <el-form-item label="绑粉数" prop="fans">
              <el-input
                v-model="form.fans"
                placeholder="请输入绑粉数"
              /> </el-form-item
          ></el-col>

          <el-col :span="12">
            <el-form-item label="套餐类型视频AI" prop="videoAiPackage">
              <el-input
                v-model="form.videoAiPackage"
                placeholder="请输入套餐类型视频AI"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="核券量目标" prop="qualityRepair">
              <el-input
                v-model="form.qualityRepair"
                placeholder="请输入核券量目标"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="老旧终端升级" prop="oldTerminalUpgrade">
              <el-input
                v-model="form.oldTerminalUpgrade"
                placeholder="请输入老旧终端升级"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="老旧套餐升级" prop="oldPackageUpgrade">
              <el-input
                v-model="form.oldPackageUpgrade"
                placeholder="请输入老旧套餐升级"
              /> </el-form-item
          ></el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="状态" prop="status">-->
<!--              <el-select-->
<!--                v-model="form.status"-->
<!--                placeholder="请选择状态"-->
<!--                clearable-->
<!--              >-->
<!--                <el-option-->
<!--                  v-for="dict in dict.type.distance_target"-->
<!--                  :key="dict.value"-->
<!--                  :label="dict.label"-->
<!--                  :value="dict.value"-->
<!--                />-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 小区业务目标导入对话框 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox
              v-model="upload.updateSupport"
            />是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link
            type="primary"
            :underline="false"
            style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate"
            >下载模板</el-link
          >
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTarget,
  getTarget,
  delTarget,
  addTarget,
  updateTarget,
  getUserDeptInfo,
  listByStatus,
} from "@/api/system/target";
import { getToken } from "@/utils/auth";
export default {
  name: "Target",
  dicts: ["distance_target", "dx_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小区业务目标表格数据
      targetList: [],
      // 小区列表
      communityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        districtCompany: null,
        businessDepartment: null,
        communityName: null,
        deptId: null,
        marketingTime: null,
        fttrTarget: null,
        penetrationRate: null,
        convergenceTarget: null,
        singleBroadbandTarget: null,
        status: 1,
        communityStatus: null,
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/target/importData",
      },

      // 表单参数
      form: {},
      // 活动天数
      activityDays: 0,
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "小区部门id不能为空", trigger: "blur" },
        ],
        // status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
        districtCompany: [
          { required: true, message: "区县分公司不能为空", trigger: "blur" },
        ],
        businessDepartment: [
          { required: true, message: "营业部不能为空", trigger: "blur" },
        ],
        communityName: [
          { required: true, message: "小区名称不能为空", trigger: "blur" },
        ],
        // marketingTime: [
        //   { required: true, message: "营销时间不能为空", trigger: "blur" },
        // ],
        fttrTarget: [
          { required: true, message: "FTTR目标值不能为空", trigger: "blur" },
        ],
        penetrationRate: [
          { required: true, message: "渗透率目标值不能为空", trigger: "blur" },
        ],
        convergenceTarget: [
          { required: true, message: "融合目标数量不能为空", trigger: "blur" },
        ],
        videoAiPackage: [
          { required: true, message: "套餐类型视频AI不能为空", trigger: "blur" },
        ],
        qualityRepair: [
          { required: true, message: "核券量目标不能为空", trigger: "blur" },
        ],
        oldTerminalUpgrade: [
          { required: true, message: "老旧终端升级不能为空", trigger: "blur" },
        ],
        oldPackageUpgrade: [
          { required: true, message: "老旧套餐升级不能为空", trigger: "blur" },
        ],
        fans: [
          { required: true, message: "绑粉数不能为空", trigger: "blur" },
        ],
        singleBroadbandTarget: [
          {
            required: true,
            message: "单宽带目标数量不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询小区业务目标列表 */
    getList() {
      this.loading = true;
      // 如果选择了小区状态筛选，调用状态筛选接口
      if (this.queryParams.communityStatus !== null && this.queryParams.communityStatus !== '') {
        listByStatus(this.queryParams.communityStatus).then((response) => {
          this.targetList = response.data || [];
          this.total = this.targetList.length;
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      } else {
        // 否则调用普通列表接口
        listTarget(this.queryParams).then((response) => {
          this.targetList = response.rows;
          this.total = response.total;
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        districtCompany: null,
        businessDepartment: null,
        communityName: null,
        deptId: null,
        marketingTime: null,
        activityStartTime: null,
        activityEndTime: null,
        fttrTarget: null,
        penetrationRate: null,
        convergenceTarget: null,
        videoAiPackage:null,
        qualityRepair:null,
        oldTerminalUpgrade:null,
        oldPackageUpgrade:null,
        singleBroadbandTarget: null,
        fans: null,
        status: 1,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      // 重置活动天数计算相关数据
      this.activityDays = 0;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 小区状态变化处理 */
    handleStatusChange() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getUserDeptData();
      this.open = true;
      this.title = "添加小区业务目标";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTarget(id).then((response) => {
        this.form = response.data;
        // 如果有活动时间数据，计算天数
        this.$nextTick(() => {
          this.calculateActivityDays();
        });
        this.open = true;
        this.title = "修改小区业务目标";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateTarget(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTarget(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除小区业务目标编号为"' + ids + '"的数据项？')
        .then(function () {
          return delTarget(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 获取用户部门数据 */
    getUserDeptData() {
      getUserDeptInfo().then((response) => {
        if (response.code === 200) {
          const data = response.data;
          // 自动填充区县分公司和营业部
          this.form.districtCompany = data.districtCompany;
          this.form.businessDepartment = data.businessDepartment;
          // 设置小区列表
          this.communityList = data.communityList || [];
        }
      }).catch(() => {
        this.$modal.msgError("获取部门信息失败");
      });
    },
    /** 小区选择变化处理 */
    handleCommunityChange(communityName) {
      // 根据选择的小区名称设置对应的deptId
      const selectedCommunity = this.communityList.find(
        (item) => item.deptName === communityName
      );
      if (selectedCommunity) {
        this.form.deptId = selectedCommunity.deptId;
      }
    },
    /** 计算活动天数和各类型目标值 */
     calculateActivityDays() {
       if (this.form.activityStartTime && this.form.activityEndTime) {
         const startDate = new Date(this.form.activityStartTime);
         const endDate = new Date(this.form.activityEndTime);

         if (endDate >= startDate) {
           // 计算天数差
           const timeDiff = endDate.getTime() - startDate.getTime();
           this.activityDays = Math.ceil(timeDiff / (1000 * 3600 * 24)) + 1; // 包含开始和结束日期

           // 根据dx_type字典计算各类型目标值并赋值给对应的表单字段
           if (this.dict.type.dx_type && this.dict.type.dx_type.length > 0) {
             console.log('dx_type字典数据:', this.dict.type.dx_type);
             this.dict.type.dx_type.forEach(dictItem => {
               const dailyStandard = parseFloat(dictItem.value) || 0;
               const totalValue = dailyStandard * this.activityDays;

               // 根据字典项的标签或值匹配对应的表单字段
               const label = dictItem.label;
               const value = totalValue.toString();

               console.log(`处理字典项: ${label}, 日标准值: ${dailyStandard}, 活动天数: ${this.activityDays}, 计算值: ${totalValue}`);

               // 根据标签名称匹配对应的表单字段
               const labelLower = label.toLowerCase();
               if (labelLower.includes('fttr')) {
                 this.form.fttrTarget = value;
                 console.log('匹配到FTTR目标值:', value);
               } else if (label.includes('渗透率')) {
                 this.form.penetrationRate = value;
                 console.log('匹配到渗透率目标值:', value);
               } else if (label.includes('融合')) {
                 this.form.convergenceTarget = value;
                 console.log('匹配到融合目标值:', value);
               } else if (label.includes('单宽带') || label.includes('宽带')) {
                 this.form.singleBroadbandTarget = value;
                 console.log('匹配到单宽带目标值:', value);
               } else if (label.includes('绑粉') || label.includes('粉丝')) {
                 this.form.fans = value;
                 console.log('匹配到绑粉目标值:', value);
               } else if (label.includes('视频AI') || (label.includes('视频') && label.includes('AI'))) {
                 this.form.videoAiPackage = value;
                 console.log('匹配到视频AI套餐目标值:', value);
               } else if (label.includes('核券') || label.includes('券量')) {
                 this.form.qualityRepair = value;
                 console.log('匹配到核券量目标值:', value);
               } else if (label.includes('老旧终端') || label.includes('终端升级')) {
                 this.form.oldTerminalUpgrade = value;
                 console.log('匹配到老旧终端升级目标值:', value);
               } else if (label.includes('老旧套餐') || label.includes('套餐升级') || label.includes('老旧套餐升级') || (label.includes('老旧') && label.includes('套餐'))) {
                 this.form.oldPackageUpgrade = value;
                 console.log('匹配到老旧套餐升级目标值:', value);
               } else {
                 console.warn(`未匹配到对应字段的字典项: ${label}`);
               }
             });
           } else {
             console.warn('dx_type字典数据为空或未加载');
           }
         } else {
           this.activityDays = 0;
           this.$message.warning('活动结束时间不能早于开始时间');
         }
       } else {
         this.activityDays = 0;
       }
     },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/target/export",
        {
          ...this.queryParams,
        },
        `target_${new Date().getTime()}.xlsx`
      );
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "小区业务目标导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "system/target/importTemplate",
        {},
        `target_template_${new Date().getTime()}.xlsx`
      );
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
          response.msg +
          "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
  },
};
</script>
